#Import libraries
import pandas
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
xlsx_files = os.listdir('../01_data/')
xlsx_files = [file for file in xlsx_files if file.startswith('export_A380') == True]
count = 0
for file in xlsx_files:
print(file)
if count<1:
df = pandas.read_excel('../01_data/'+file)
cols = df.columns.tolist() #Names of columns
columns = []
for col in cols:
tempo = col.replace('.', '_')
tempo = tempo.replace(' ', '_')
columns.append(tempo.lower()) #Rename columns
df.columns = columns
else:
df2 = pandas.read_excel('../01_data/'+file)
cols = df2.columns.tolist() #Names of columns
columns = []
for col in cols:
tempo = col.replace('.', '_')
tempo = tempo.replace(' ', '_')
columns.append(tempo.lower()) #Rename columns
df2.columns = columns
df = pandas.concat([df, df2])
count+=1
df = df.drop(["item"],axis = 1) #Delete some useless columns
df = df.convert_objects(convert_numeric=True)
#df = df.infer_objects()
#df.dtypes
print(df.shape)
df.head()
#Check conditions
df = df[df["acms_fp"] == 10] #ACMS FP = 10 (eq. FWSFP = 1)
df = df[df["apubvop"] == 1] #APU Bleed Valve Open (1 mean OPEN)
df = df[df["lcbvcl"] == 0] #Xbleed Valves Open (1 mean CLOSE)
df = df[df["cfvcl"] == 0] #Xbleed Valves Open (1 mean CLOSE)
df = df[df["rcbvcl"] == 0] #Xbleed Valves Open (1 mean CLOSE)
print(df.shape)
df = df[(df["hpv_1"] == 1) & (df["hpv_2"] == 1) & (df["hpv_3"] == 1) & (df["hpv_4"] == 1)] #HPV Close (1 mean CLOSE, see ICD20221-002_digital icd p28)
df = df[(df["prv_1"] == 1) & (df["prv_2"] == 1) & (df["prv_3"] == 1) & (df["prv_4"] == 1)] #PRV Close (1 mean CLOSE, see ICD20221-002_digital icd p28)
print(df.shape)
df = df[(df["sav_1"] == 0) & (df["sav_2"] == 0) & (df["sav_3"] == 0) & (df["sav_4"] == 0)] #SAV Close (1 mean OPEN according to Temperature)
print(df.shape)
df = df[(df["fcvcl_1"] == 0) & (df["fcvcl_2"] == 0) & (df["fcvcl_3"] == 0) & (df["fcvcl_4"] == 0)] #FCV Open (1 mean CLOSE, see ICD20221-002_digital icd_PADS; $$5.3.3)
df = df[(df["n2act_1"] == 0) & (df["n2act_2"] == 0) & (df["n2act_3"] == 0) & (df["n2act_4"] == 0)] #N2 = 0
print(df.shape)
#Compute for each precoolers the difference between the bleed temperature and the median of the 3 others
df["PCE_1"] = df["bldt_1"] - df[["bldt_2","bldt_3","bldt_4"]].median(axis=1)
df["PCE_2"] = df["bldt_2"] - df[["bldt_1","bldt_3","bldt_4"]].median(axis=1)
df["PCE_3"] = df["bldt_3"] - df[["bldt_1","bldt_2","bldt_4"]].median(axis=1)
df["PCE_4"] = df["bldt_4"] - df[["bldt_1","bldt_2","bldt_3"]].median(axis=1)
df.head()
aircraft_registration = pandas.unique(df['tailnb']) #List of all aircraft registration
time_aircraft = 1
pp1 = PdfPages('../03_results/A380_Precooler_Median.pdf') #PDF where plots are saved
for aircraft in aircraft_registration: #For each aircraft
print(aircraft,time_aircraft,'/',len(aircraft_registration))
df_aircraft = df[df['tailnb'] == aircraft] #Select only this aircraft among all the dataframe
df_aircraft = df_aircraft.sort_values(by=['modified_date']) #Sort the dataframe with date
date_aircraft = pandas.unique(df_aircraft['date']) #List of unique date
MaxByUplink = np.zeros((len(date_aircraft),5), dtype=object) #Array initialization
count = 0
for date in date_aircraft: #For each date
MaxByUplink[count,0] = date #First column is date
df_aircraft_date = df_aircraft[df_aircraft['date'] == date] #Select only this date among the dataframe
for i in range(1,5):
pce = 'PCE_'+str(i)
MaxByUplink[count,i] = df_aircraft_date[pce].max() #Compute for each precooler the max of the median for 1 uplink
count = count + 1
MaxByUplink = pandas.DataFrame(MaxByUplink, columns=['Date','Max_PCE_1','Max_PCE_2','Max_PCE_3','Max_PCE_4']) #Convert in dataframe
#MaxByUplink
start_date = np.datetime64(MaxByUplink['Date'][0]) #First date where we have data
end_date = np.datetime64(MaxByUplink['Date'][len(MaxByUplink)-1]) #Last date where we have data
MaxBy8Uplinks = np.zeros((int((end_date-start_date).astype(int)/480000000)+1,5), dtype=object) #Array initialization
count = 0
for i in range(len(MaxBy8Uplinks)):
df_tempo = MaxByUplink[MaxByUplink['Date'] >= start_date]
df_tempo = df_tempo[df_tempo['Date'] < start_date + 480000000]
if len(df_tempo) > 0:
MaxBy8Uplinks[count,0] = start_date + 240000000
for j in range(1,5):
pce = 'Max_PCE_'+str(j)
MaxBy8Uplinks[count,j] = df_tempo[pce].max()
count = count + 1
start_date = start_date + 480000000
if start_date > end_date:
break
MaxBy8Uplinks = MaxBy8Uplinks[:count,] #Keep only not empty row
MaxBy8Uplinks = pandas.DataFrame(MaxBy8Uplinks, columns=['Date','Max8_PCE_1','Max8_PCE_2','Max8_PCE_3','Max8_PCE_4']) #Convert in dataframe
#MaxBy8Uplinks
plt.rcParams["figure.figsize"] = [25,9]
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_1'])
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_2'])
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_3'])
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_4'])
plt.legend()
plt.title("Difference between the bleed temperature and the median of the 3 others for each PCE for the aircraft "+aircraft)
plt.ylim(ymax=150);plt.ylim(ymin=-150)
plt.xlabel('Date');plt.ylabel('Difference between the bleed temperature and the median')
plt.savefig(pp1, format='pdf')
plt.show() #Plot the figure
time_aircraft = time_aircraft + 1
pp1.close()
aircraft = 'A6-EDL'
df_aircraft = df[df['tailnb'] == aircraft]
df_aircraft = df_aircraft.sort_values(by=['modified_date'])
print(len(df_aircraft))
date_aircraft = pandas.unique(df_aircraft['date'])
MaxByUplink = np.zeros((len(date_aircraft),5), dtype=object) #Array initialization
count = 0
for date in date_aircraft:
MaxByUplink[count,0] = date
df_aircraft_date = df_aircraft[df_aircraft['date'] == date]
for i in range(1,5):
pce = 'PCE_'+str(i)
MaxByUplink[count,i] = df_aircraft_date[pce].max()
count = count + 1
MaxByUplink = pandas.DataFrame(MaxByUplink, columns=['Date','Max_PCE_1','Max_PCE_2','Max_PCE_3','Max_PCE_4'])
MaxByUplink
start_date = np.datetime64(MaxByUplink['Date'][0])
end_date = np.datetime64(MaxByUplink['Date'][len(MaxByUplink)-1])
MaxBy8Uplinks = np.zeros((int((end_date-start_date).astype(int)/480000000)+1,5), dtype=object) #Array initialization
count = 0
for i in range(len(MaxBy8Uplinks)):
df_tempo = MaxByUplink[MaxByUplink['Date'] >= start_date]
df_tempo = df_tempo[df_tempo['Date'] < start_date + 480000000]
if len(df_tempo) > 0:
MaxBy8Uplinks[count,0] = start_date + 240000000
for j in range(1,5):
pce = 'Max_PCE_'+str(j)
MaxBy8Uplinks[count,j] = df_tempo[pce].max()
count = count + 1
start_date = start_date + 480000000
if start_date > end_date:
break
MaxBy8Uplinks = MaxBy8Uplinks[:count,]
MaxBy8Uplinks = pandas.DataFrame(MaxBy8Uplinks, columns=['Date','Max8_PCE_1','Max8_PCE_2','Max8_PCE_3','Max8_PCE_4'])
MaxBy8Uplinks
window_size = 9
SumDifference = np.zeros((int(len(MaxBy8Uplinks)/9+1),5), dtype=object) #Array initialization
for i in range(int(len(MaxBy8Uplinks)/9+1)):
window = MaxBy8Uplinks[i*9:i*9+9]
if len(window) > 0:
SumDifference[i,0] = window['Date'][i*9] + 480000000 * int(window_size/2)
for j in range(1,5):
pce = 'Max8_PCE_'+str(j)
SumDifference[i,j] = window[pce].sum()
SumDifference = pandas.DataFrame(SumDifference, columns=['Date','SumMax_PCE_1','SumMax_PCE_2','SumMax_PCE_3','SumMax_PCE_4'])
SumDifference = SumDifference[SumDifference['SumMax_PCE_1'] != 0]
SumDifference
plt.rcParams["figure.figsize"] = [25,9]
plt.plot(SumDifference['Date'],SumDifference['SumMax_PCE_1'])
plt.plot(SumDifference['Date'],SumDifference['SumMax_PCE_2'])
plt.plot(SumDifference['Date'],SumDifference['SumMax_PCE_3'])
plt.plot(SumDifference['Date'],SumDifference['SumMax_PCE_4'])
plt.legend()
plt.title("On a moving windows of 9 consecutives FCs, sum of the maximum difference value for each PCE for the aircraft "+aircraft)
plt.xlabel('Date');plt.ylabel('Sum of the maximum difference value')
plt.show()
plt.rcParams["figure.figsize"] = [25,9]
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_1'])
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_2'])
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_3'])
plt.plot(MaxBy8Uplinks['Date'],MaxBy8Uplinks['Max8_PCE_4'])
plt.legend()
plt.title("Difference between the bleed temperature and the median of the 3 others for each PCE for the aircraft "+aircraft)
plt.xlabel('Date');plt.ylabel('Difference between the bleed temperature and the median')
plt.show()
df = pandas.read_excel('../01_data/export_A380__TBR361J0_20180126-20180202.xlsx')
df = df[df['tailNb'] == 'A6-EOS']